# Sample Logstash configuration for creating a simple
# Beats -> Logstash -> Elasticsearch pipeline.
# @author ${author}
# @since ${date}
# @desc  ${table.comment!} => logstash 配置文件
# 将这个文件防置在 logstash 的 config 文件夹下,回到 logstash 的 bin文件夹调用cmd
# 执行 logstash.bat -f ../config/${table.layuiEntityName}task.conf

input {
  jdbc {
    jdbc_driver_library => "${driversPath}"
    jdbc_driver_class => "${dataSourceDrivername}"
    jdbc_connection_string => "${dataSourceUrl}"
    jdbc_user => "${dataSourceUsername}"
    jdbc_password => "${dataSourcePassword}"
    jdbc_default_timezone => "Asia/Shanghai"
    statement => "SELECT * FROM ${table.name} WHERE ${table.updateColumn.columnName} > :sql_last_value AND ${table.updateColumn.columnName} < NOW() ORDER BY ${table.updateColumn.columnName} DESC"
    tracking_column => "${table.updateColumn.propertyName}"
    tracking_column_type => "timestamp"
    use_column_value => true
    schedule => "*/5 * * * * *"
  }
}

filter {
  mutate {
    rename => {
<#assign ES_KEY_COLUMN=""/>
<#list table.fields as field>
    <#if field.keyFlag><#assign ES_KEY_COLUMN=field.propertyName/></#if>
      "${field.name}" => "${field.propertyName}"
</#list>
    }
    remove_field => ["thumbnum", "favournum"]
  }
}

output {
  elasticsearch {
    hosts => "${ES_URIS}"
    user => "${ES_USERNAME}"
    password => "${ES_PASSWORD}"
    index => "${table.name}"
    document_id => "%{${ES_KEY_COLUMN}}"
  }
}
